package com.binary.coder.gift.core.domain.ai.factory;

import com.binary.coder.gift.core.domain.ai.model.HunYuanModelInputParam;
import com.binary.coder.gift.core.domain.ai.model.HunYuanModeloutputParam;
import com.tencentcloudapi.hunyuan.v20230901.models.ChatCompletionsRequest;
import com.tencentcloudapi.hunyuan.v20230901.models.ChatCompletionsResponse;
import com.tencentcloudapi.hunyuan.v20230901.models.Message;

import java.util.Arrays;

/**
 * @author atao
 * @version 1.0.0
 * @ClassName HunYuanFactory.java
 * @Description 混元模型参数工厂
 * @createTime 2024年07月11日 17:02:00
 */
public class HunYuanFactory {


    public static HunYuanModelInputParam buildHunYuanModelInputParam(String input) {
        HunYuanModelInputParam data = new HunYuanModelInputParam();
        data.setAction("ChatCompletions");
        data.setVersion("2023-09-01");
        data.setModel("hunyuan-lite");
        data.setStream(false);
        data.setRegion("ap-beijing");
        Message message = new Message();
        message.setRole("user");
        message.setContent(input);
        data.setMessages(Arrays.asList(message));
        return data;
    }

    public static ChatCompletionsRequest buildChatCompletionsRequest(HunYuanModelInputParam param) {
        ChatCompletionsRequest request = new ChatCompletionsRequest();
        request.setMessages((Message[]) param.getMessages().toArray());
        request.setModel(param.getModel());
        request.setStream(param.getStream());
        return request;
    }

    public static void fillHunYuanModeloutputParam(ChatCompletionsResponse source,HunYuanModeloutputParam target) {
        target.setChoices(Arrays.asList(source.getChoices()));
        target.setCreated(source.getCreated());
        target.setErrorMsg(source.getErrorMsg());
        target.setNote(source.getNote());
        target.setId(source.getId());
        target.setRequestId(source.getRequestId());
        target.setUsage(source.getUsage());
    }

}
